#include <sys/epoll.h>
#include <iostream>
#include <unistd.h>
// epoll_creat函数参数所需要的大小
#define EPOLL_SIZE 200
class Epoll
{
public:
    // 创建epoll模型
    Epoll()
    {
        _epfd = epoll_create(EPOLL_SIZE);
        if (_epfd < 0)
        {
            std::cout << "epoll_create fail..." << std::endl;
            exit(6);
        }
    }
    // 修改红黑树的数据
    void Ctl(int op, int sock, int events)
    {
        epoll_event eve;
        eve.data.fd = sock;
        eve.events = events;
        int ret = epoll_ctl(_epfd, op, sock, &eve);
        if (ret < 0)
        {
            std::cout << "epoll_ctl fail..." << std::endl;
            exit(7);
        }
    }
    // 等待事件
    int Wait(epoll_event *eve, int maxnum, int timeout)
    {
        int num = epoll_wait(_epfd, eve, maxnum, timeout);
        if (num < 0)
        {
            std::cout << "epoll_wait..." << std::endl;
            exit(8);
        }
        return num;
    }
    // 析构epoll模型
    ~Epoll()
    {
        if (_epfd > 0)
            close(_epfd);
    }

private:
    int _epfd;
};